package com.ygxsk.carhome.ui.paintbook;

import android.Manifest;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.afollestad.materialdialogs.MaterialDialog;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.ClickUtils;
import com.blankj.utilcode.util.ColorUtils;
import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.KeyboardUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.NetworkUtils;
import com.blankj.utilcode.util.PathUtils;
import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;
import com.flyco.roundview.RoundTextView;
import com.gyf.immersionbar.ImmersionBar;
import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.XXPermissions;
import com.hjq.toast.Toaster;
import com.kathline.library.content.ZFileBean;
import com.kathline.library.content.ZFileConfiguration;
import com.kathline.library.content.ZFileContent;
import com.kongzue.dialogx.dialogs.PopTip;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.util.SmartGlideImageLoader;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;
import com.trello.rxlifecycle4.android.ActivityEvent;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;
import com.umeng.socialize.shareboard.ShareBoardConfig;
import com.umeng.socialize.shareboard.SnsPlatform;
import com.umeng.socialize.utils.ShareBoardlistener;
import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.runtime.Permission;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.alertview.AlertView;
import com.ygxsk.carhome.alertview.OnItemClickListener;
import com.ygxsk.carhome.constant.ConstantApi;
import com.ygxsk.carhome.constant.ConstantSign;
import com.ygxsk.carhome.constant.ExtraKey;
import com.ygxsk.carhome.constant.ExtraValue;
import com.ygxsk.carhome.event.EventBusQRCode;
import com.ygxsk.carhome.listener.AuthorityCallbackListener;
import com.ygxsk.carhome.listener.DoSomeThingListener;
import com.ygxsk.carhome.permission.PermissionSetting;
import com.ygxsk.carhome.permission.RuntimeRationale;
import com.ygxsk.carhome.response.PaintBookingItemBean;
import com.ygxsk.carhome.response.PaintBookingSumHistoryOutSideBean;
import com.ygxsk.carhome.retrofit.AddLogUpLoadInfo;
import com.ygxsk.carhome.retrofit.ApiException;
import com.ygxsk.carhome.retrofit.ApiRequestSubListener;
import com.ygxsk.carhome.retrofit.ApiService;
import com.ygxsk.carhome.retrofit.ErrorConsumer;
import com.ygxsk.carhome.retrofit.NetworkManager;
import com.ygxsk.carhome.retrofit.ResponseTransformer;
import com.ygxsk.carhome.sys.PermissionInterceptor;
import com.ygxsk.carhome.sys.PermissionNameConvert;
import com.ygxsk.carhome.ui.ErrorActivity;
import com.ygxsk.carhome.ui.adapter.PaintBookingSumHistoryAdapter;
import com.ygxsk.carhome.ui.zxing.MyBGAQRCodeActivity;
import com.ygxsk.carhome.utils.CommUtils;
import com.ygxsk.carhome.utils.DemoImage;
import com.ygxsk.carhome.utils.RC4Utils;
import com.ygxsk.carhome.views.MyLinearLayoutManager;
import com.ygxsk.integrated.retrofit.Parameterkey;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.File;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.functions.Consumer;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;

/*
 * @Author:itchenqi175@163.com
 * @Time:2023-09-12  09:10
 * @Description:车辆喷涂的历史记录页面
 */
public class PaintBookingSumHistoryActivity extends ErrorActivity implements EasyPermissions.PermissionCallbacks {

    //扫描二维码需要的部分权限
    private static final int REQUEST_CODE_QRCODE_PERMISSIONS = 2;

    @BindView(R.id.refreshLayoutInBookingSumHistory)
    SmartRefreshLayout refreshLayoutInBookingSumHistory;

    @BindView(R.id.recyclerViewInBookingSumHistory)
    RecyclerView recyclerViewInBookingSumHistory;


    /**
     * 最后一条上传的id的信息内容
     */
    private int pagination_upLoad = Parameterkey.pageNum_default_first;

    private ArrayList<PaintBookingItemBean> mDataResources = new ArrayList<PaintBookingItemBean>();
    //适配器内容
    private PaintBookingSumHistoryAdapter paintBookingSumHistoryAdapter;

    //点击分享的时候，填充的分享面板的信息,2023-12-12 14:43:48 也用在喷涂预约的扫描喷涂房里的二维码。
    private PaintBookingItemBean paintBookingItemBean_shareInfo;

    private UMShareListener mShareListener;

    private ShareAction mShareAction;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mActivityInstance = this;

        if (mDataResources == null) {
            mDataResources = new ArrayList<>();
        }

        initloading();

        initViews();

        gainDatas();

        mShareListener = new CustomShareListener(this);

        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }

    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_paint_booking_sum_history;
    }


    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();

        ImmersionBar.with(this)//
                .titleBar(R.id.toolbarygxskout)
                .fitsSystemWindows(true)//解决状态栏和布局重叠问题，任选其一，默认为false，当为true时一定要指定statusBarColor()，不然状态栏为透明色，还有一些重载方法
                //.statusBarColor(R.color.colorPrimary)//
                //.navigationBarColor(R.color.colorPrimary)//
                //.keyboardEnable(true)
                .init();

    }

    @Override
    protected void initToolBar(ToolbarHelper toolbarHelper) {

        toolbarHelper.setTitle(getString(R.string.paint_booking_sum_history));
        toolbarHelper.setVersionName(true, AppUtils.getAppVersionName());
        toolbarHelper.setLayoutClose(false, "", null);
        toolbarHelper.setLayoutLeft(true, R.drawable.backicon, new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //搜索客户信息，优先关闭软键盘
                KeyboardUtils.hideSoftInput(mActivityInstance);

                methodBack();

            }
        });

        //添加潜在客户的按钮
        toolbarHelper.setLayoutRight(false, 0, "", null);

//        toolbarHelper.setLayoutRight(true, 1, getString(R.string.title_right_addlead), new ClickUtils.OnDebouncingClickListener() {
//            @Override
//            public void onDebouncingClick(View v) {
//
//                //快速双加的限制，
//                Bundle extra_bundle = new Bundle();
//                //标志【添加】
//                extra_bundle.putInt(ExtraKey.EXTRA_JUMPFROM_WHERE, ExtraValue.VALUE_JUMP_FORM_LEAD_ADD);
//                ActivityUtils.startActivity(extra_bundle, LeadAddSubmitActivity.class);
//
//            }
//        });

    }

    @Override
    protected void onClickNodata(View v) {

        gainDatas();

    }

    @Override
    protected void initViews() {

        recyclerViewInBookingSumHistory.setLayoutManager(new MyLinearLayoutManager(this));

        //列表填充
        paintBookingSumHistoryAdapter = new PaintBookingSumHistoryAdapter(R.layout.paint_booking_sum_history_adapter, mDataResources);
        recyclerViewInBookingSumHistory.setAdapter(paintBookingSumHistoryAdapter);
        paintBookingSumHistoryAdapter.notifyDataSetChanged();

        //下拉刷新和加载更多
        refreshLayoutInBookingSumHistory.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {

                refreshLayout.getLayout().post(new Runnable() {
                    @Override
                    public void run() {

//                    LogUtils.d(ConstantSign.LOGCAT_NOMAL + "refreshLayoutInBooking--下拉刷新执行");

                        gainDatas();

                        refreshLayout.finishRefresh();

                    }
                });

            }

            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {

                refreshLayout.getLayout().post(new Runnable() {
                    @Override
                    public void run() {

//                          LogUtils.d(ConstantSign.LOGCAT_NOMAL + "refreshLayoutInBooking--下拉刷新执行");

                        getServerDatas();

                        refreshLayout.finishRefresh();

                    }
                });

            }

        });

        //列表小按钮的点击 查看二维码信息
        paintBookingSumHistoryAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
            @Override
            public void onItemChildClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {

                PaintBookingItemBean paintBookingItemBean = (PaintBookingItemBean) adapter.getItem(position);

                if (paintBookingItemBean != null) {

                    //是用来做分享的填充拼接的信息,并且用来做喷涂预约的二维码扫码。
                    paintBookingItemBean_shareInfo = paintBookingItemBean;

                    switch (view.getId()) {

//                        case R.id.textViewPaintBookingQrCode: {//预约二维码 按钮
//                            gainData_look_qrCode(paintBookingItemBean.getReservationSiteId(), paintBookingItemBean.getSiteNo());
//                            break;
//                        }

                        case R.id.textViewPaintBookingQrCode: {//变更为扫描二维码 按钮，2023-12-12 10:10:00

//                            gainData_look_qrCode(paintBookingItemBean.getReservationSiteId(), paintBookingItemBean.getSiteNo());
                            //变动为主动扫描二维码的功能
                            //提前获取相机相册的权限设置
                            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {

                                requestCodeQRCodePermissions();

                            } else {

                                requestCodePermissionsXXPermissions();

                            }

                            break;
                        }

                        case R.id.textViewPaintBookingCancel: {//取消预约的按钮

                            //二次确认弹窗
                            CommUtils.checkDialog(mAlertView);
                            mAlertView = new AlertView(StringUtils.getString(R.string.clearaddorsubmitsuretitletips),
                                    StringUtils.getString(R.string.clearaddorsubmitsuremessage),
                                    StringUtils.getString(R.string.clearcachecancel),
                                    new String[]{StringUtils.getString(R.string.clearaddorsubmitsure)},
                                    null, mActivityInstance, AlertView.Style.Alert, new OnItemClickListener() {//
                                @Override
                                public void onItemClick(Object o, int position) {

                                    if (position != AlertView.CANCELPOSITION) {

                                        gainData_paintBooking_cancel(paintBookingItemBean.getReservationId(), paintBookingItemBean.getSiteNo());

                                    }
                                }
                            });

                            mAlertView.setCancelable(true);
                            mAlertView.show();

                            break;
                        }

                        default:
                            break;
                    }

                }


            }
        });

    }

    @AfterPermissionGranted(REQUEST_CODE_QRCODE_PERMISSIONS)
    private void requestCodeQRCodePermissions() {

        try {
            //do
//            String[] perms = {Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.WRITE_EXTERNAL_STORAGE};
            String[] perms = {Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE};

            if (EasyPermissions.hasPermissions(this, perms)) {

                openMain();

            } else {

                CommUtils.checkMaterialDialog(materialDialog);

                materialDialog = CommUtils.authorityRequest(PaintBookingSumHistoryActivity.this, ConstantSign.MATERIALDIALOG_AUTHORITY_CONTENT_CAMERA_STORAGE, new AuthorityCallbackListener() {
                    @Override
                    public void doSomeThing() {

                        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "已经弹出了 权限内容弹窗");

                        CommUtils.checkMaterialDialog(materialDialog);

                        EasyPermissions.requestPermissions(PaintBookingSumHistoryActivity.this, StringUtils.getString(R.string.imageselectstr_audio), REQUEST_CODE_QRCODE_PERMISSIONS, perms);

                    }
                });

            }

        } catch (Exception e) {
            //catch
            e.printStackTrace();
        }


    }


    //android13的权限判断
    private void requestCodePermissionsXXPermissions() {

        //                          || !XXPermissions.isGranted(MyBGAQRCodeActivity.this, com.hjq.permissions.Permission.READ_MEDIA_VIDEO)//
        //                          || !XXPermissions.isGranted(MyBGAQRCodeActivity.this, com.hjq.permissions.Permission.READ_MEDIA_AUDIO)//
        if (!XXPermissions.isGranted(PaintBookingSumHistoryActivity.this, com.hjq.permissions.Permission.CAMERA)//
                || !XXPermissions.isGranted(PaintBookingSumHistoryActivity.this, com.hjq.permissions.Permission.READ_MEDIA_IMAGES)) {

            CommUtils.checkMaterialDialog(materialDialog);

            materialDialog = CommUtils.authorityRequest(PaintBookingSumHistoryActivity.this, ConstantSign.MATERIALDIALOG_AUTHORITY_CONTENT_ALBUM, new AuthorityCallbackListener() {
                @Override
                public void doSomeThing() {

                    CommUtils.checkMaterialDialog(materialDialog);

                    XXPermissions.with(PaintBookingSumHistoryActivity.this)
                            // 适配分区存储应该这样写
                            //.permission(Permission.Group.STORAGE)
                            // 不适配分区存储应该这样写
                            .permission(com.hjq.permissions.Permission.CAMERA)//
                            .permission(com.hjq.permissions.Permission.READ_MEDIA_IMAGES)//
//                                    .permission(com.hjq.permissions.Permission.READ_MEDIA_VIDEO)//
//                                    .permission(com.hjq.permissions.Permission.READ_MEDIA_AUDIO)//
                            //).permission(com.hjq.permissions.Permission.MANAGE_EXTERNAL_STORAGE
//                                                        .interceptor(new PermissionInterceptor())
                            .request(new OnPermissionCallback() {

                                @Override
                                public void onGranted(@NonNull List<String> permissions, boolean allGranted) {

                                    if (!allGranted) {
                                        // TODO: 2024/1/23 18:50 权限这里要不要给提示？权限没通过
                                        return;
                                    }

                                    Toaster.show(String.format(getString(R.string.demo_obtain_permission_success_hint), PermissionNameConvert.getPermissionString(PaintBookingSumHistoryActivity.this, permissions)));

                                    openMain();

                                }
                            });
                }
            });

        } else {

            openMain();

        }

    }

    //通用的设置权限弹窗的逻辑
    private void openMain() {

        Bundle bundle = new Bundle();
        bundle.putInt(ExtraKey.EXTRA_QRCODE_INFO, 0);
        bundle.putInt(ExtraKey.BGAQRCODE_KEY, ExtraValue.BGAQRCODE_VALUE_FROM_PAINT_BOOK_SUMHISTORY);
        ActivityUtils.startActivity(bundle, MyBGAQRCodeActivity.class);

    }

    //查看二维码的信息
    private void gainData_paintBooking_cancel(String _reservationId, String _siteNo) {

        HashMap<String, Object> map = new HashMap<>();
//
//        map.put(Parameterkey.reservationSiteId, _reservationSiteId);
        map.put(Parameterkey.reservationId, _reservationId);
//        map.put(Parameterkey.pagination, pagination_upLoad);//传递的页码
//        map.put(Parameterkey.pageSize, Parameterkey.pageSize_default);//,搜索关键字

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_GETQRCODEBYID_URL);//请求数字标识
        addLogUpLoadInfo.setUrlPath(ApiService.getQrCodeById_url);//url地址
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
        addLogUpLoadInfo.setToastToUser(false);//展示给用户的标志
        addLogUpLoadInfo.setHashMapParameter(map);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
                .refundReservation(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
                        MediaType.parse(ApiService.HEADER_JSON)))
//                .getQrCodeById("45")
                .compose(PaintBookingSumHistoryActivity.this.bindUntilEvent(ActivityEvent.DESTROY))//
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<Boolean>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);

                        CommUtils.checkMaterialDialog(materialDialog);

                        //{"data":"","message":"请选择待使用的记录","code":"21405"}
//                        method_show_QRCode_dialog(_siteNo,"");
                        //{"data":"","message":"预约时间已过期","code":"21406"}
                        //特定提示
                        if (!TextUtils.equals(serverCode, ConstantSign.RESPONSE_STRING_21406)) {

                            if (!TextUtils.isEmpty(serverMessage)) {
                                ToastUtils.showShort(serverMessage);
                            }

                        } else {

                            CommUtils.checkDialog(mAlertView);
                            mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, serverMessage, true);
                            mAlertView.show();

                        }

                    }
                })).doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Throwable {

//                        CommUtils.checkMaterialDialog(materialDialog);
                        method_create_materialDialog(mActivityInstance, ConstantSign.TIPS_SUBMIT);

                    }
                }).subscribe(new Consumer<Boolean>() {
                    @Override
                    public void accept(Boolean booleanValue) throws Throwable {

                        //一句话提示
                        CommUtils.checkMaterialDialog(materialDialog);

                        if (booleanValue) {

                            PopTip.show(getResources().getString(R.string.user_cancel_paintbooking_success)).iconSuccess();

                            //取消预约成功之后，给列表刷新，目的为了将这条数据放置在下边；
//                            if (mDataResources!=null&&!mDataResources.isEmpty()){
//                                mDataResources.clear();
//                            }
//
//                            if (paintBookingSumHistoryAdapter!=null){
//                                paintBookingSumHistoryAdapter.notifyDataSetChanged();
//                            }

                            //直接重新获取
                            gainDatas();

                        } else {

                            PopTip.show(getResources().getString(R.string.user_cancel_paintbooking_fail)).iconWarning();

                        }

                    }
                }, new ErrorConsumer() {

                    @Override
                    protected void error(ApiException apiException) {
                        //页面报错；
                    }
                });

    }

    //查看二维码的信息
    private void gainData_look_qrCode(String _reservationSiteId, String _siteNo) {

        HashMap<String, Object> map = new HashMap<>();
//
        map.put(Parameterkey.reservationSiteId, _reservationSiteId);
//        map.put(Parameterkey.pagination, pagination_upLoad);//传递的页码
//        map.put(Parameterkey.pageSize, Parameterkey.pageSize_default);//,搜索关键字

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_GETQRCODEBYID_URL);//请求数字标识
        addLogUpLoadInfo.setUrlPath(ApiService.getQrCodeById_url);//url地址
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
        addLogUpLoadInfo.setToastToUser(false);//展示给用户的标志
        addLogUpLoadInfo.setHashMapParameter(map);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
                .getQrCodeById(_reservationSiteId)
//                .getQrCodeById("45")
                .compose(PaintBookingSumHistoryActivity.this.bindUntilEvent(ActivityEvent.DESTROY))//
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<String>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);

                        //{"data":"","message":"请选择待使用的记录","code":"21405"}
//                        method_show_QRCode_dialog(_siteNo,"");
                        //{"data":"","message":"预约时间已过期","code":"21406"}
                        //特定提示
                        if (!TextUtils.equals(serverCode, ConstantSign.RESPONSE_STRING_21406)) {

                            if (!TextUtils.isEmpty(serverMessage)) {
                                ToastUtils.showShort(serverMessage);
                            }

                        } else {

                            CommUtils.checkDialog(mAlertView);
                            mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, serverMessage, true);
                            mAlertView.show();

                        }

                    }
                })).doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Throwable {

                    }
                }).subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String stringValue) throws Throwable {

                        //展示二维码信息
                        method_show_QRCode_dialog(_siteNo, stringValue);


                    }
                }, new ErrorConsumer() {

                    @Override
                    protected void error(ApiException apiException) {
                        //页面报错；
                    }
                });

    }

    @Override
    protected void gainDatas() {

        //这个接口内就是刷新全部内容
//        pagination_upLoad = Parameterkey.pageNum_default_first;//重置
        pagination_upLoad = Parameterkey.pageNum_default_first;//重置

        if (mDataResources != null && !mDataResources.isEmpty()) {
            mDataResources.clear();
        }

        //适配器刷新
        if (paintBookingSumHistoryAdapter != null) {
            paintBookingSumHistoryAdapter.notifyDataSetChanged();
        }

        if (NetworkUtils.isConnected()) {

            getServerDatas();

            //因为要筛选 业务类型；
//            gainSmartGoType(null);

        } else {
            netWorkError();
            setEnableLoadmore(refreshLayoutInBookingSumHistory, false);
        }

    }

    private void getServerDatas() {

        HashMap<String, Object> map = new HashMap<>();

        map.put(Parameterkey.shopId, mSession.getShopInfoId());

//        map.put(Parameterkey.shopInfoId, mSession.getShopInfoId());
//        map.put(Parameterkey.customerId, _customerId);//填充搜索出来的这个客户的 唯一id
        map.put(Parameterkey.pagination, pagination_upLoad);//传递的页码
        map.put(Parameterkey.pageSize, Parameterkey.pageSize_default);//,搜索关键字

//        map.put(Parameterkey.vehicleNo, keyWord_upLoad);//,搜索关键字
//        map.put(Parameterkey.hasFee, hasFee_upLoad);//是否产生费用 是否产生费用:0：否；1：是
//        map.put(Parameterkey.isPayment, isPayment_upLoad);//是否已缴费 是否已缴费(0:否，1:是)
//        map.put(Parameterkey.businessType, businessType_upLoad);//业务类型的筛选，是修车还是维保

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_GETMYRESERVATIONSITE_URL_URL);//请求数字标识
        addLogUpLoadInfo.setUrlPath(ApiService.getMyReservationSite_url);//url地址
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
        addLogUpLoadInfo.setToastToUser(true);//展示给用户的标志
        addLogUpLoadInfo.setHashMapParameter(map);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
                .getMyReservationSite(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
                        MediaType.parse(ApiService.HEADER_JSON)))
                .compose(PaintBookingSumHistoryActivity.this.bindUntilEvent(ActivityEvent.DESTROY))//
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<PaintBookingSumHistoryOutSideBean>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);

                        //methodNotSuccessData(what_method, serverCode, serverMessage);

                        if (mDataResources != null && mDataResources.isEmpty()) {
                            CommUtils.checkCurrently((ErrorActivity) mActivityInstance,//
                                    serverCode,//
                                    R.drawable.errorsear,//
                                    serverMessage,//
                                    getString(R.string.nulldatanow));
                        }

                        // TODO: 2023-08-15 21:38 要不要给提示

                    }
                })).doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Throwable {
                        loadingGone();
                        setEnableLoadmore(refreshLayoutInBookingSumHistory, true);
                    }
                }).subscribe(new Consumer<PaintBookingSumHistoryOutSideBean>() {
                    @Override
                    public void accept(PaintBookingSumHistoryOutSideBean paintBookingSumHistoryOutSideBean) throws Throwable {

                        if (paintBookingSumHistoryOutSideBean != null) {

                            ArrayList<PaintBookingItemBean> bookingOutsideBeanList = paintBookingSumHistoryOutSideBean.getDataList();

                            if (bookingOutsideBeanList != null && !bookingOutsideBeanList.isEmpty()) {
                                if (mDataResources != null) {
                                    mDataResources.addAll(bookingOutsideBeanList);
                                }
                            }

                        }

                        //这里也不用管是下拉刷新或者上拉加载更多，直接判断是否为空，
                        if (mDataResources != null && mDataResources.isEmpty()) {
                            if (refreshLayoutInBookingSumHistory != null) {
                                refreshLayoutInBookingSumHistory.setEnableLoadMore(false);
                            }
                            fillNullDataView(StringUtils.getString(R.string.nulldatanow), R.drawable.errorsear);
                        }

                        if (paintBookingSumHistoryAdapter != null) {
                            paintBookingSumHistoryAdapter.notifyDataSetChanged();
                        }

                        //给分页值
                        pagination_upLoad = paintBookingSumHistoryOutSideBean.getNextPagination();

                        //对列表改造：
                        if (pagination_upLoad == Parameterkey.GET_NEXT_PAGINATION) {
                            setFinishLoadMoreWithNoMoreData(refreshLayoutInBookingSumHistory, true);
                        } else {
                            setEnableLoadmore(refreshLayoutInBookingSumHistory, true);
                        }

                    }
                }, new ErrorConsumer() {

                    @Override
                    protected void error(ApiException apiException) {
                        //页面报错；
                    }
                });


    }

    //自定义的弹窗关于二维码的信息
    private MaterialDialog materialDialogCustomView;

    //弹窗的操作：展示获取到的优惠券的信息；
    private void method_show_QRCode_dialog(String _siteNo, String _imageUrlBase64) {

        View viewCard = View.inflate(mActivityInstance, R.layout.qrcodemiddlepopu, null);

        if (viewCard != null) {

            //标题 卡券的
            TextView textViewQrName = (TextView) viewCard.findViewById(R.id.textviewqrname);
            //填充房间号的名称内容
            textViewQrName.setText(_siteNo);

            //图片的内容  imageviewpaintbookingqrcode
            ImageView imageViewQRCode = (ImageView) viewCard.findViewById(R.id.imageviewpaintbookingqrcode);
            //关闭 按钮
            RoundTextView textViewCardCancel = (RoundTextView) viewCard.findViewById(R.id.textviewqrcodecancel);
            //保存为图片的按钮
            RoundTextView textViewCardSure = (RoundTextView) viewCard.findViewById(R.id.textviewqrcodesave);
            //友盟分享的内容
//            RoundTextView textViewQrcodeShare = (RoundTextView) viewCard.findViewById(R.id.textViewQrcodeShare);

            String imagePath = PathUtils.getExternalAppFilesPath() + File.separator + ConstantSign.DOWNAPP + File.separator + ConstantSign.IMG + TimeUtils.getNowString() + ConstantSign.IMG_POSTFIX;
            FileUtils.createOrExistsFile(imagePath);

            boolean resultValue = DemoImage.base64ToImage(_imageUrlBase64, imagePath);
            //boolean resultValue = DemoImage.base64ToImage(_imageUrlBase64, PathUtils.getExternalAppFilesPath() + File.separator + ConstantSign.IMG + TimeUtils.getNowString() + ConstantSign.IMG_POSTFIX);

            if (resultValue) {

                Glide.with(PaintBookingSumHistoryActivity.this)
                        .load(imagePath)
                        .placeholder(R.drawable.icon_errorfang)//
                        .error(R.drawable.icon_errorfang)//
                        .fitCenter()
                        .diskCacheStrategy(DiskCacheStrategy.NONE)//动态获取新值不缓存
//                        .override(120, 60)
                        .into(imageViewQRCode);

                //PathUtils.getExternalAppFilesPath() + File.separator + ConstantSign.IMG + TimeUtils.getNowString() + ConstantSign.IMG_POSTFIX

//                点击查看大图
                imageViewQRCode.setOnClickListener(new ClickUtils.OnDebouncingClickListener() {
                    @Override
                    public void onDebouncingClick(View v) {
                        //验证码的查看大图
                        new XPopup.Builder(PaintBookingSumHistoryActivity.this)
                                .asImageViewer(imageViewQRCode, //
                                        imagePath,//
                                        new SmartGlideImageLoader())//
                                .show();
                    }
                });

            }

            if (textViewCardCancel != null) {
                textViewCardCancel.setOnClickListener(new ClickUtils.OnDebouncingClickListener() {
                    @Override
                    public void onDebouncingClick(View v) {

                        //此时 弹窗是已经被弹出的
                        if (materialDialogCustomView != null) {
                            materialDialogCustomView.dismiss();
                        }

                    }
                });
            }

            if (textViewCardSure != null) {

                textViewCardSure.setOnClickListener(new ClickUtils.OnDebouncingClickListener() {
                    @Override
                    public void onDebouncingClick(View v) {

                        //存储图片的权限：
                        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {

                            //获取权限
                            if (!AndPermission.hasPermissions(mActivityInstance, Permission.WRITE_EXTERNAL_STORAGE)
                                    || !AndPermission.hasPermissions(mActivityInstance, Permission.READ_EXTERNAL_STORAGE)) {

                                CommUtils.checkMaterialDialog(materialDialog);

                                materialDialog = CommUtils.authorityRequest(mActivityInstance, ConstantSign.MATERIALDIALOG_AUTHORITY_CONTENT_STORAGE, new AuthorityCallbackListener() {
                                    @Override
                                    public void doSomeThing() {

                                        CommUtils.checkMaterialDialog(materialDialog);

                                        //添加访问权限内容
                                        AndPermission.with(PaintBookingSumHistoryActivity.this)
                                                .runtime()//
                                                .permission(Permission.READ_EXTERNAL_STORAGE, //
                                                        Permission.WRITE_EXTERNAL_STORAGE)//
                                                .rationale(new RuntimeRationale())//
                                                .onGranted(new com.yanzhenjie.permission.Action<List<String>>() {
                                                    @Override
                                                    public void onAction(List<String> permissions) {

                                                        methodOpenImage(imagePath);

                                                    }
                                                }).onDenied(new com.yanzhenjie.permission.Action<List<String>>() {
                                                    @Override
                                                    public void onAction(List<String> permissions) {

                                                        ToastUtils.showShort(ConstantSign.NEEDPERMISS_PHONE);

                                                        PermissionSetting permissionSetting = new PermissionSetting(mActivityInstance);

                                                        if (AndPermission.hasAlwaysDeniedPermission(PaintBookingSumHistoryActivity.this, permissions)) {
                                                            permissionSetting.showSetting(ConstantApi.PERMISSION_NORMAL, PaintBookingSumHistoryActivity.this, permissions);
                                                        }

                                                    }
                                                }).start();

                                    }
                                });

                            } else {

                                methodOpenImage(imagePath);

                            }


                        } else {


                            if (!XXPermissions.isGranted(PaintBookingSumHistoryActivity.this, com.hjq.permissions.Permission.READ_MEDIA_IMAGES)) {

                                CommUtils.checkMaterialDialog(materialDialog);

                                materialDialog = CommUtils.authorityRequest(mActivityInstance, ConstantSign.MATERIALDIALOG_AUTHORITY_CONTENT_ALBUM, new AuthorityCallbackListener() {

                                    @Override
                                    public void doSomeThing() {

                                        CommUtils.checkMaterialDialog(materialDialog);

                                        XXPermissions.with(PaintBookingSumHistoryActivity.this)
                                                .permission(com.hjq.permissions.Permission.READ_MEDIA_IMAGES)//
                                                .interceptor(new PermissionInterceptor())
                                                .request(new OnPermissionCallback() {

                                                    @Override
                                                    public void onGranted(@NonNull List<String> permissions, boolean allGranted) {

                                                        if (!allGranted) {
                                                            return;
                                                        }

                                                        Toaster.show(String.format(getString(R.string.demo_obtain_permission_success_hint),
                                                                PermissionNameConvert.getPermissionString(PaintBookingSumHistoryActivity.this, permissions)));

                                                        methodOpenImage(imagePath);

                                                    }
                                                });

                                    }
                                });


                            } else {

                                methodOpenImage(imagePath);

                            }

                        }

                    }
                });
            }


//            //分享图片 友盟分享
//            if (textViewQrcodeShare != null) {
//
//                textViewQrcodeShare.setOnClickListener(new ClickUtils.OnDebouncingClickListener() {
//                    @Override
//                    public void onDebouncingClick(View v) {
//
//                        //获取权限
//                        if (!AndPermission.hasPermissions(mActivityInstance, Permission.WRITE_EXTERNAL_STORAGE)
//                                || !AndPermission.hasPermissions(mActivityInstance, Permission.READ_EXTERNAL_STORAGE)) {
//
//                            CommUtils.authorityRequest(mActivityInstance, ConstantSign.MATERIALDIALOG_AUTHORITY_CONTENT_STORAGE, new AuthorityCallbackListener() {
//                                @Override
//                                public void doSomeThing() {
//
//                                    //添加访问权限内容
//                                    AndPermission.with(PaintBookingSumHistoryActivity.this)
//                                            .runtime()//
//                                            .permission(Permission.READ_EXTERNAL_STORAGE, //
//                                                    Permission.WRITE_EXTERNAL_STORAGE)//
//                                            .rationale(new RuntimeRationale())//
//                                            .onGranted(new com.yanzhenjie.permission.Action<List<String>>() {
//                                                @Override
//                                                public void onAction(List<String> permissions) {
//
//                                                    methodShareImage(imagePath);
//
//                                                }
//                                            }).onDenied(new com.yanzhenjie.permission.Action<List<String>>() {
//                                                @Override
//                                                public void onAction(List<String> permissions) {
//
//                                                    ToastUtils.showShort(ConstantSign.NEEDPERMISS_PHONE);
//
//                                                    PermissionSetting permissionSetting = new PermissionSetting(mActivityInstance);
//
//                                                    if (AndPermission.hasAlwaysDeniedPermission(PaintBookingSumHistoryActivity.this, permissions)) {
//                                                        permissionSetting.showSetting(ConstantApi.PERMISSION_NORMAL, PaintBookingSumHistoryActivity.this, permissions);
//                                                    }
//
//                                                }
//                                            }).start();
//
//                                }
//                            });
//
//                        } else {
//
////                          LogUtils.d(ConstantSign.LOGCAT_NOMAL + "正常的权限已经打开，可以执行拍照操作");
//                            methodShareImage(imagePath);
//
//                        }
//                    }
//                });
//            }


            //激发 弹窗弹出内容
            materialDialogCustomView = new MaterialDialog.Builder(PaintBookingSumHistoryActivity.this)
                    .customView(viewCard, false)
                    .contentColor(ColorUtils.getColor(R.color.buttonnomcolor))//
                    //.positiveText("确定")
                    .positiveColor(ColorUtils.getColor(R.color.dark))
                    //.negativeText("取消")
                    .canceledOnTouchOutside(false)
                    .show();

            //materialDialog.getTitleView().setTextSize(16f);

        }

    }

    private void methodShareImage(String _imageUrlBase64) {

        //必须要关闭弹窗，不然有遮挡
        if (materialDialogCustomView != null) {
            materialDialogCustomView.dismiss();
            materialDialogCustomView.cancel();
        }

        /*增加自定义按钮的分享面板*/
        mShareAction = new ShareAction(PaintBookingSumHistoryActivity.this)
                .setDisplayList(SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.WEIXIN_FAVORITE)
//                .addButton("复制文本", "复制文本", "umeng_socialize_copy", "umeng_socialize_copy")
//                .addButton("复制链接", "复制链接", "umeng_socialize_copyurl", "umeng_socialize_copyurl")
                .setShareboardclickCallback(new ShareBoardlistener() {
                    @Override
                    public void onclick(SnsPlatform snsPlatform, SHARE_MEDIA share_media) {

//                        if (snsPlatform.mShowWord.equals("复制文本")) {
//                            Toast.makeText(PaintBookingSumHistoryActivity.this, "复制文本按钮", Toast.LENGTH_LONG).show();
//                        } else if (snsPlatform.mShowWord.equals("复制链接")) {
//                            Toast.makeText(PaintBookingSumHistoryActivity.this, "复制链接按钮", Toast.LENGTH_LONG).show();
//                        } else {

                        UMWeb web = new UMWeb(_imageUrlBase64);

                        if (paintBookingItemBean_shareInfo != null) {

                            web.setTitle(paintBookingItemBean_shareInfo.getSiteNo());//预约的房间

                            String description = StringUtils.getString(R.string.textbookingtimeday) + paintBookingItemBean_shareInfo.getUseTime()//
                                    + StringUtils.getString(R.string.textbookingrentbegintime) + paintBookingItemBean_shareInfo.getRentBeginTime()//
                                    + StringUtils.getString(R.string.textbookingrentendtime) + paintBookingItemBean_shareInfo.getRentEndTime();//

                            web.setDescription(description);//预约时段，

                        } else {

                            web.setTitle(getString(R.string.bookingtxtqrcode));//预约的房间
                            web.setDescription(getString(R.string.bookingtxtqrcode));

                        }

                        web.setThumb(new UMImage(PaintBookingSumHistoryActivity.this, R.mipmap.ic_launcher));

                        new ShareAction(PaintBookingSumHistoryActivity.this).withMedia(web)
                                .setPlatform(share_media)
                                .setCallback(mShareListener)
                                .share();
//                        }
                    }
                });
        //配置页面底部2的方式：官方样例
        ShareBoardConfig config = new ShareBoardConfig();
        config.setMenuItemBackgroundShape(ShareBoardConfig.BG_SHAPE_NONE);
        config.setIndicatorVisibility(false);
        config.setShareboardBackgroundColor(Color.WHITE);
        mShareAction.open(config);

    }

    //直接打开文件的路径，打开文件
    private void methodOpenImage(String _imageUrlBase64) {

        //直接打开到文件夹
        final ZFileConfiguration configuration = new ZFileConfiguration.Build()
                .filePath(PathUtils.getExternalAppFilesPath() + File.separator + ConstantSign.DOWNAPP + File.separator)
                .boxStyle(ZFileConfiguration.STYLE2)
//                .sortordBy(ZFileConfiguration.BY_DEFAULT)
                .sortordBy(ZFileConfiguration.BY_DATE)//按照日期的顺序排序
                .sortord(ZFileConfiguration.DESC)//倒序排列
                .maxLength(1)
                .maxLengthStr("最多选1个！")
                .useSAF(false)
                .build();

        ZFileContent.getZFileHelp()
                .setConfiguration(configuration)
                .start(PaintBookingSumHistoryActivity.this);

    }

    //给二维码图片重新保存
    private void methodSaveImage(String _imageUrlBase64) {

//        String imageDownloads = PathUtils.getExternalDcimPath() + File.separator +ConstantSign.IMG + TimeUtils.getNowString() + ConstantSign.IMG_POSTFIX;
//
//        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "imageDicm-->" + imageDownloads);
//
//        //itchen-->imageDicm-->/storage/emulated/0/Download/img2023-10-18 18:39:57.jpg
//        //itchen-->imageDicm-->/storage/emulated/0/Pictures/img2023-10-18 18:52:25.jpg
//
//        boolean toImage = DemoImage.base64ToImage(_imageUrlBase64, imageDownloads);


        //通知相册 刷新一次

    }

    //执行拷贝的能力:添加原始的能力
    private void methodCopy(String _imagePathOriginal) {

        //获取相机相册的路径
//      String imagePath_photo_album = PathUtils.getExternalAppDcimPath() + File.separator + ConstantSign.IMG + TimeUtils.getNowString() + ConstantSign.IMG_POSTFIX;
        String imagePath_photo_album = PathUtils.getExternalDcimPath() + File.separator + ConstantSign.IMG + TimeUtils.getNowString() + ConstantSign.IMG_POSTFIX;

        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "imagePath_photo_album-->" + imagePath_photo_album);
        //itchen-->imagePath_photo_album-->/storage/emulated/0/DCIM/img2023-10-18 17:56:30.jpg

        File fileOriginal = new File(_imagePathOriginal);
        File fileTarget = new File(imagePath_photo_album);

        // 保存二维码到相册；给图片复制到相册
        boolean sure = FileUtils.copy(fileOriginal, fileTarget);
        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "sure-->" + sure);

//                        FileUtils.copy(fileOriginal,fileTarget,new FileUtils.OnReplaceListener(){
//                            @Override
//                            public boolean onReplace(File srcFile, File destFile) {
//
//                                LogUtils.d(ConstantSign.LOGCAT_NOMAL+"srcFile-->"+srcFile);
//                                LogUtils.d(ConstantSign.LOGCAT_NOMAL+"destFile-->"+destFile);
//                                //进度监听原始
//                                LogUtils.d(ConstantSign.LOGCAT_NOMAL+"sure-->拷贝完毕");
//                                return true;
//                            }
//                        });

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThreadPaintBookingSum(EventBusQRCode eventBusQRCode) {

        if (eventBusQRCode != null) {

            if (eventBusQRCode.getMessage() == ExtraValue.BGAQRCODE_VALUE_FROM_PAINT_BOOK_SUMHISTORY) {

                //扫描的二维码是被加密的。
                String qrCodeResult_encrypted = eventBusQRCode.getContent();
//                LogUtils.d(ConstantSign.LOGCAT_NOMAL + "原始的扫码获取到的内容-qrCodeResult_decrypt：-->" + qrCodeResult_encrypted);

                if (!TextUtils.isEmpty(qrCodeResult_encrypted)) {

                    if (qrCodeResult_encrypted.contains(Parameterkey.QRCODE_HTTP)) {

                        CommUtils.linkJumpDialog(PaintBookingSumHistoryActivity.this, PaintBookingSumHistoryActivity.this, qrCodeResult_encrypted);

                    } else {

                        //这里要对扫码做解密处理
                        try {

                            String qrCodeResult_decrypt = RC4Utils.decry_RC4(qrCodeResult_encrypted, RC4Utils.pub_key);
//                            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "qrCodeResult_decrypt：-->" + qrCodeResult_decrypt);
                            // itchen-->qrCodeResult_decrypt：-->{"param":{"spraySiteId":4},"sign":"SprayReservation"}

                            QrCodePaintBookBean qrCodePaintBookBean = JSON.parseObject(qrCodeResult_decrypt, QrCodePaintBookBean.class);

                            if (qrCodePaintBookBean != null) {

                                String param = qrCodePaintBookBean.getParam();
                                LogUtils.d(ConstantSign.LOGCAT_NOMAL + "param：-->" + param);
                                //itchen-->param：-->{"spraySiteId":4}

                                //标志是哪个模块：在历史记录页面不用判断这个标志
                                String sign = qrCodePaintBookBean.getSign();

                                if (!TextUtils.isEmpty(param) && !TextUtils.isEmpty(sign)) {

                                    //第一种方式： 一个简单的弹窗。
//                                CommUtils.checkDialog(mAlertView);
//                                mAlertView = CommUtils.method_showAlertViewTwoButton(mActivityInstance,//
//                                        StringUtils.getString(R.string.clearcachecancel),//取消
//                                        StringUtils.getString(R.string.clearcachedelete),//删除
//                                        StringUtils.getString(R.string.paitbook_toast_history),//确定供电
//                                        false, new OnItemClickListener() {//
//                                            @Override
//                                            public void onItemClick(Object o, int position) {
//                                                if (position != AlertView.CANCELPOSITION) {
//                                                    //用户确认之后 立即调用接口
//                                                    method_gainData_by_qrCode_for_updateForScanQrCode(param);
//                                                }
//                                                //取消 就取消 不执行任何操作。
//                                            }
//                                        });
//                                mAlertView.show();

                                    if (TextUtils.equals(sign, Parameterkey.SprayReservation)) {

                                        //第二种方式：确认了是【喷涂房预约扫码的功能】
                                        method_show_QRCode_has_parse_success_dialog_tips(param);

                                    }

//                                else if(qrCodeResult_encrypted.contains(Parameterkey.QRCODE_HTTP)){
//
//                                    //有可能扫描了别的二维码，发现是打开的链接
//                                    CommUtils.linkJumpDialog(PaintBookingSumHistoryActivity.this, PaintBookingSumHistoryActivity.this, qrCodeResult_encrypted);
//
//                                }else{
//
//                                    CommUtils.textJumpDialog(PaintBookingSumHistoryActivity.this, PaintBookingSumHistoryActivity.this, qrCodeResult_encrypted);
//
//                                }


                                } else {
                                    PopTip.show(param).iconWarning();
                                }

                            } else {

                                if (qrCodeResult_encrypted.contains(Parameterkey.QRCODE_HTTP)) {

                                    //有可能扫描了别的二维码，发现是打开的链接
                                    CommUtils.linkJumpDialog(PaintBookingSumHistoryActivity.this, PaintBookingSumHistoryActivity.this, qrCodeResult_encrypted);

                                } else {

                                    CommUtils.textJumpDialog(PaintBookingSumHistoryActivity.this, PaintBookingSumHistoryActivity.this, qrCodeResult_encrypted);

                                }

                            }

                            //区分一个标识符号：
//                    if (qrCodeResult.startsWith(Parameterkey.QRCODE_PREFIX)) {

                            //如果扫码的内容为空，那么需要提示
                            //这是跳转到-客户关怀的根据二维码获取 优惠券的详情
                        /*if (flag_jumpfrom_where == ExtraValue.VALUE_JUMP_FORM_RICE_TICKET_OUT_ACTIVITY) {
                            method_gainData_by_qrCode_for_rice_ticked(qrCodeResult);
                        } else if (flag_jumpfrom_where == ExtraValue.VALUE_JUMP_FORM_CARD_MAIN_ACTIVITY) {
                            method_gainData_by_qrCode_for_customer_care_card(qrCodeResult);
                        } else {
                            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "没有执行-调用核销码 获取详情接口");
                        }*/

//                    } else if (qrCodeResult.contains(Parameterkey.QRCODE_HTTP)) {
//                        CommUtils.linkJumpDialog(PaintBookingSumHistoryActivity.this, PaintBookingSumHistoryActivity.this, qrCodeResult);
//                    } else {
//                        CommUtils.textJumpDialog(PaintBookingSumHistoryActivity.this, PaintBookingSumHistoryActivity.this, qrCodeResult);
//                    }

                        } catch (Exception e) {

                            if (e != null) {
                                LogUtils.d(ConstantSign.LOGCAT_NOMAL + "扫码解析报错->" + e.getMessage());
                            }

                            throw new RuntimeException(e);
                        }

                    }


                } else {

                    if (TextUtils.isEmpty(qrCodeResult_encrypted)) {//服务站运营经理的初始值-1说明没有赋值，提交不过去
                        CommUtils.checkDialog(mAlertView);
                        mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getString(R.string.check_qrcode_upload), true);
                        mAlertView.show();
                    }

                }

            }

        }

    }


    //弹窗确认,扫码出加密数据，并且解析成功之后弹窗。
    private void method_show_QRCode_has_parse_success_dialog_tips(String _param) {

        //执行该弹窗的时候要清空弹层以上的所有弹层
        CommUtils.checkMaterialDialog(materialDialogCustomView);

        //引导客户认证的弹窗：
        View viewCard = View.inflate(mActivityInstance, R.layout.paint_booking_popu, null);

        //客户未完成认证的弹窗文字提示
//        TextView textViewQRMessage = (TextView) viewCard.findViewById(R.id.tv_name_paintbook_popu_title);
//        textViewQRMessage.setText(message_content);

        //确认供电按钮
        RoundTextView textViewToSignatureQRCodeCreateTips = (RoundTextView) viewCard.findViewById(R.id.textviewsurepaintbook);
        //关闭按钮
        RoundTextView textViewSignatureCancelCreateTips = (RoundTextView) viewCard.findViewById(R.id.textviewpaintbookcancel);

        //clicks
        //确认供电按钮
        textViewToSignatureQRCodeCreateTips.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                method_gainData_by_qrCode_for_updateForScanQrCode(_param);

                if (materialDialogCustomView != null) {
                    materialDialogCustomView.dismiss();
                }

            }
        });

        //关闭
        textViewSignatureCancelCreateTips.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //此时 弹窗是已经被弹出的
                if (materialDialogCustomView != null) {
                    materialDialogCustomView.dismiss();
                }

            }
        });

        //激发 弹窗弹出内容
        materialDialogCustomView = new MaterialDialog.Builder(PaintBookingSumHistoryActivity.this)
                .customView(viewCard, false)
                .contentColor(ColorUtils.getColor(R.color.buttonnomcolor))//
                //.positiveText("确定")
                .positiveColor(ColorUtils.getColor(R.color.dark))
                //.negativeText("取消")
                .canceledOnTouchOutside(false)
                .show();


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (mDataResources != null && !mDataResources.isEmpty()) {
            mDataResources.clear();
//            mDataResources = null;
        }

        if (paintBookingSumHistoryAdapter != null) {
            paintBookingSumHistoryAdapter.notifyDataSetChanged();
            paintBookingSumHistoryAdapter = null;
        }

        if (mDataResources != null) {
            mDataResources = null;
        }

        if (mShareListener != null) {
            mShareListener = null;
        }

        if (paintBookingItemBean_shareInfo != null) {
            paintBookingItemBean_shareInfo = null;
        }

        EventBus.getDefault().unregister(this);

        //reset
        UMShareAPI.get(this).release();

    }


    //根据扫描的二维码信息，传递给后台 开启电源 开始喷涂，执行这条预约数据。
    private void method_gainData_by_qrCode_for_updateForScanQrCode(String _rqCode_content_param) {

//      LogUtils.d(ConstantSign.LOGCAT_NOMAL + "调用 餐券发放-餐券核销接口--method_gainData_by_qrCode_for_rice_ticked");

        HashMap<String, Object> map = new HashMap<>();
        map.put(Parameterkey.shopInfoId, mSession.getShopInfoId());
        map.put(Parameterkey.reservationSiteId, paintBookingItemBean_shareInfo.getReservationSiteId());//预约单明细ID

//        map.put(Parameterkey.spraySiteId, _rqCode_content);//扫码可获取场地ID

        //{"spraySiteId":4}
        //去掉json串前边和后边的括号
       /* String splitFrontAndBehind = _rqCode_content_param.substring(1, _rqCode_content_param.length() - 1);
//        传参的形式是：
//        {
//                "accessCode": 5808,
//                "spraySiteId": 4
//        }
        //添加核销码字段拼接上
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("{");
        stringBuffer.append(splitFrontAndBehind);//去掉第一位和最后一位的结果
        stringBuffer.append(",");//需要拼接成一个json，用逗号分割的
        stringBuffer.append("\"");//需要拼接成一个json，用逗号分割的
        stringBuffer.append(Parameterkey.accessCode);
        stringBuffer.append("\"");
        stringBuffer.append(":");
        stringBuffer.append(paintBookingItemBean_shareInfo.getAccessCode());
        stringBuffer.append("}");*/

        //测试代码：测试后台扫码出现的多个参数
//        _rqCode_content_param = "{\"spraySiteId\":4,\"tokenCode\":\"123456\"}";

        String stringBuffertoString = CommUtils.splitFrontAndBehindAddOneParam(_rqCode_content_param, Parameterkey.accessCode, paintBookingItemBean_shareInfo.getAccessCode());
        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "stringBuffer-->" + stringBuffertoString);

        //日志勿删除
        //如果是多个参数，那么形式就是这种
        //itchen-->stringBuffer-->{"spraySiteId":4,"tokenCode":"123456","accessCode":"5808"}

        //勿删日志
        //字符串形式的
        //itchen-->stringBuffer-->
        //数字形式的
        //itchen-->stringBuffer-->{"spraySiteId":4,accessCode:5808}

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_UPDATEFORSCANQRCODE);//请求数字标识
        addLogUpLoadInfo.setUrlPath(ApiService.updateForScanQrCode_url);//url地址
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
        addLogUpLoadInfo.setToastToUser(false);//展示给用户的标志
        addLogUpLoadInfo.setHashMapParameter(map);

        //原始代码
//        String jsonObject = JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
                .updateForScanQrCode(RequestBody.create(stringBuffertoString, MediaType.parse(ApiService.HEADER_JSON)))
                .compose(PaintBookingSumHistoryActivity.this.bindUntilEvent(ActivityEvent.DESTROY))
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<String>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);

                        CommUtils.checkMaterialDialog(materialDialog);
                        //这里要给一个醒目提示？

                        if (!TextUtils.isEmpty(serverMessage)) {
//                            PopTip.show(serverMessage).iconWarning();
                            CommUtils.checkDialog(mAlertView);
                            mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, serverMessage, true);
                            mAlertView.show();

                        } else {
                            PopTip.show(getString(R.string.action_abnormal)).iconWarning();
                        }

                    }
                })).doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Throwable {

//                        CommUtils.checkMaterialDialog(materialDialog);
                        method_create_materialDialog(mActivityInstance, ConstantSign.TIPS_SUBMIT);

                    }
                }).subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String string) throws Throwable {

                        CommUtils.checkMaterialDialog(materialDialog);

                        // TODO: 2023-12-12 14:37 传递完毕之后，执行什么？直接提示提交成功？
//                        if (couponCustomer != null) {
//                            method_show_dist_dialog(_rqCode_content, couponCustomer);
//                        } else {
//                            ToastUtils.showShort(getString(R.string.action_abnormal));
//                        }

                        methodSubmitSuccess(PaintBookingSumHistoryActivity.this, new DoSomeThingListener() {
                            @Override
                            public void doSomeThing() {
                                //是要重新刷新列表，变更状态的

                                gainDatas();
                                //弹出一个确认弹出，确认送电 开始喷涂预约的能力。


                            }
                        });

                    }
                }, new ErrorConsumer() {

                    @Override
                    protected void error(ApiException apiException) {

                        CommUtils.checkMaterialDialog(materialDialog);

                        if (apiException != null) {
                            if (!TextUtils.isEmpty(apiException.getDisplayMessage())) {
                                LogUtils.d(ConstantSign.LOGCAT_NOMAL + "执行的报错内容是-->" + apiException.getDisplayMessage());
                                ToastUtils.showShort(apiException.getDisplayMessage());
                            }
                        }

                    }
                });


    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        /** attention to this below ,must add this**/
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);

        List<ZFileBean> list = ZFileContent.getZFileHelp().getSelectData(getBaseContext(), requestCode, resultCode, data);


//        StringBuilder sb = new StringBuilder();

//        for (ZFileBean bean : list) {
//            //sb.append(bean).append("\n\n");
//            sb.append(bean.getFilePath()).append("\n\n");
//        }

//        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "选中图片路径是-->" + sb.toString());

        //itchen-->选中图片路径是-->ZFileBean{fileName='img2023-10-18 19:32:31.jpg', isFile=true, filePath='/storage/emulated/0/Android/data/com.ygxsk.carhome/files/downapp/img2023-10-18 19:32:31.jpg', date='2023-10-18 19:32:31', originalDate='1697628751000', size='15.75 KB', originaSize=16130}


//        mainResultTxt.setText(sb.toString());

        if (list != null && !list.isEmpty()) {

            String imagePath = list.get(0).getFilePath();
            //这里选中完毕 是直接分享的
            methodShareImage(imagePath);

        }

    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
    }

    @Override
    public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) {
        //同意 权限的操作
        // TODO: 2023-06-12 16:03 这里是执行扫描的操作

    }

    @Override
    public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) {

        //未能同意权限的操作
//        if (requestCode == PRC_PHOTO_PICKER) {
//            //Toast.makeText(this, "您拒绝了「图片选择」所需要的相关权限!", Toast.LENGTH_SHORT).show();
//            ToastUtils.showShort("您拒绝了「图片选择」所需要的相关权限!");
//        } else

        if (requestCode == REQUEST_CODE_QRCODE_PERMISSIONS) {

            //拒绝了扫描二维码的权限
            ToastUtils.showShort(R.string.you_refuse_permission_qrcode);

        }

    }


    private static class CustomShareListener implements UMShareListener {

        private WeakReference<PaintBookingSumHistoryActivity> mActivity;

        private CustomShareListener(PaintBookingSumHistoryActivity activity) {
            mActivity = new WeakReference(activity);
        }

        @Override
        public void onStart(SHARE_MEDIA platform) {

        }

        @Override
        public void onResult(SHARE_MEDIA platform) {

            if (platform.name().equals("WEIXIN_FAVORITE")) {
                Toast.makeText(mActivity.get(), platform + StringUtils.getString(R.string.share_favorite_successed), Toast.LENGTH_SHORT).show();
            } else {
                if (platform != SHARE_MEDIA.MORE
                        && platform != SHARE_MEDIA.SMS
                        && platform != SHARE_MEDIA.EMAIL
                        && platform != SHARE_MEDIA.FLICKR
                        && platform != SHARE_MEDIA.FOURSQUARE
                        && platform != SHARE_MEDIA.TUMBLR
                        && platform != SHARE_MEDIA.POCKET
                        && platform != SHARE_MEDIA.PINTEREST
                        && platform != SHARE_MEDIA.INSTAGRAM
                        && platform != SHARE_MEDIA.YNOTE
                        && platform != SHARE_MEDIA.EVERNOTE) {
                    Toast.makeText(mActivity.get(), platform + StringUtils.getString(R.string.share_successed), Toast.LENGTH_SHORT).show();
                }

            }
        }

        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
            if (platform != SHARE_MEDIA.MORE && platform != SHARE_MEDIA.SMS
                    && platform != SHARE_MEDIA.EMAIL
                    && platform != SHARE_MEDIA.FLICKR
                    && platform != SHARE_MEDIA.FOURSQUARE
                    && platform != SHARE_MEDIA.TUMBLR
                    && platform != SHARE_MEDIA.POCKET
                    && platform != SHARE_MEDIA.PINTEREST
                    && platform != SHARE_MEDIA.INSTAGRAM
                    && platform != SHARE_MEDIA.YNOTE
                    && platform != SHARE_MEDIA.EVERNOTE) {

                Toast.makeText(mActivity.get(), platform + StringUtils.getString(R.string.share_failed), Toast.LENGTH_SHORT).show();

            }

        }

        @Override
        public void onCancel(SHARE_MEDIA platform) {

            Toast.makeText(mActivity.get(), platform + StringUtils.getString(R.string.share_canceled), Toast.LENGTH_SHORT).show();
        }
    }


    @Override
    protected void methodBack() {

        methodBackFinish();

    }
}